<?php
	class ContentModel extends CI_Model {
		// 表名
		static $homeworkTable = "school_homework";
		static $newsTable = "school_news";
		static $notifyTable = "school_notify";
		static $announceTable = "school_announce";
		static $videoTable = "school_video";
		static $albumCategoryTable = "school_album_category";
		static $albumTable = "school_album";
		static $mailTable = "school_mail";
		static $moralTable = "school_moral";
		static $moralTimelineTable = "school_moral_timeline";
		static $moralTimelineSubjectTable = "school_moral_timeline_subject";
		static $moralActivityTable = "school_moral_activity";
		static $moralRemarkTable = "school_moral_remark";
		static $moralRemarkResultTable = "school_moral_remark_result";
		static $studentTable = "school_student";
		static $phoneBookTable = "school_phone_book";
		static $subjectContentTable = "school_subject_content";
		static $homeworkSubmitTable = "school_homework_submit";
		static $albumCategoryByAdminTable = "school_album_category_by_admin";

	    public function __construct() {
	        parent::__construct();
	    }

	    // 获取作业列表
	    public function get_homework_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}' ";
			// // 校区id
			// if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
			// campus_id改成字符串
			// 校区id
			if(isset($params['campusId'])) $where .= " AND FIND_IN_SET('{$params['campusId']}', `campus_id`)";
	    	// 班级id
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_id`)";
			// 班级id数组
			if(isset($params['classIdArr'])) {
				if($params['classIdArr']) {
					$whereStr = " AND (";
					$arr = array();
					foreach($params['classIdArr'] as $classId) {
						array_push($arr, "FIND_IN_SET('{$classId}', `class_id`)");
					}
					$str = implode(' OR ', $arr);
					$whereStr = $whereStr . $str . ")";
					$where .= $whereStr;
				} else {
					$where .= " AND 0";
				}

			}
			// 通过日期筛选
			if(isset($params['date'])) {
				$dateStart = $params['date'] . ' 00:00:00';
				$dateEnd = $params['date'] . ' 23:59:59';
				$where .= " AND `createtime` >= '{$dateStart}' AND `createtime` <= '{$dateEnd}'";
			}
			// 通过课程筛选
			if(isset($params['lesson_id'])) {
				$where .= " AND `lesson_id` = '{$params['lesson_id']}'";
			}
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `homework_title` LIKE '%{$params['title']}%'";
			}
			$this->db->where($where);
			$this->db->order_by('updatetime', 'DESC');
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$homeworkTable);
	    	
	    	return $this->db->get(self::$homeworkTable)->result_array();
	    }
	    // 获取作业详情
	    public function get_homework_info($homeworkId){
	    	$where = "`id`='{$homeworkId}'";
	    	$homeworkInfo = $this->db->where($where)->get(self::$homeworkTable)->row_array();
	    	return $homeworkInfo;
	    }
	    // 获取动态列表
	    public function get_news_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 班级id
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_id`)";
			// 班级id数组
			if(isset($params['classIdArr'])) {
				if($params['classIdArr']) {
					$whereStr = " AND (";
					$arr = array();
					foreach($params['classIdArr'] as $classId) {
						array_push($arr, "FIND_IN_SET('{$classId}', `class_id`)");
					}
					$str = implode(' OR ', $arr);
					$whereStr = $whereStr . $str . ")";
					$where .= $whereStr;
				} else {
					$where .= " AND 0";
				}

			}
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}' ";
			// // 校区id
			// if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
			// campus_id改成字符串
			// 校区id
			if(isset($params['campusId'])) $where .= " AND FIND_IN_SET('{$params['campusId']}', `campus_id`)";
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `news_title` LIKE '%{$params['title']}%'";
			}
			// 定时发布
			if(isset($params['isCron'])) {
				$where .= " AND `is_cron`='{$params['isCron']}'";
			}
			$this->db->where($where);
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按更新时间
				$this->db->order_by('updatetime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$newsTable);
	    	
	    	return $this->db->get(self::$newsTable)->result_array();
	    }
	    // 获取动态详情
	    public function get_news_info($newsId){
	    	$where = "`id`='{$newsId}'";
	    	$newsInfo = $this->db->where($where)->get(self::$newsTable)->row_array();
	    	return $newsInfo;
	    }
	    // 获取通知列表
	    public function get_notify_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id	
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_id`)";
			// 班级id数组
			if(isset($params['classIdArr'])) {
				if($params['classIdArr']) {
					$whereStr = " AND (";
					$arr = array();
					foreach($params['classIdArr'] as $classId) {
						array_push($arr, "FIND_IN_SET('{$classId}', `class_id`)");
					}
					$str = implode(' OR ', $arr);
					$whereStr = $whereStr . $str . ")";
					$where .= $whereStr;
				} else {
					$where .= " AND 0";
				}

			}
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}' ";
			// // 校区id
			// if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
			// campus_id改成字符串
			// 校区id
			if(isset($params['campusId'])) $where .= " AND FIND_IN_SET('{$params['campusId']}', `campus_id`)";
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `notify_title` LIKE '%{$params['title']}%'";
			}
			$this->db->where($where);
			// 是否设置优先排序
			if(isset($params['orderByFirst'])) {
				$this->db->order_by($params['orderByFirst']['order'], $params['orderByFirst']['sort']);
			}
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按更新时间
				$this->db->order_by('updatetime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$notifyTable);
	    	return $this->db->get(self::$notifyTable)->result_array();
	    }
	    // 获取通知详情
	    public function get_notify_info($notifyId){
	    	$where = "`id`='{$notifyId}'";
	    	$notifyInfo = $this->db->where($where)->get(self::$notifyTable)->row_array();
	    	return $notifyInfo;
	    }
	    // 获取校园公告列表
	    public function get_announce_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
	    	// 删除状态
	    	if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			$this->db->where($where);
			// 是否设置优先排序
			if(isset($params['orderByFirst'])) {
				$this->db->order_by($params['orderByFirst']['order'], $params['orderByFirst']['sort']);
			}
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按更新时间
				$this->db->order_by('updatetime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$announceTable);
	    	
	    	return $this->db->get(self::$announceTable)->result_array();
	    }
	    // 获取通知详情
	    public function get_announce_info($announceId){
	    	$where = "`id`='{$announceId}'";
	    	$notifyInfo = $this->db->where($where)->get(self::$announceTable)->row_array();
	    	return $notifyInfo;
	    }
	    // 获取相册分类
	    public function get_album_category($params){
			// 分页
			if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	$where = " is_delete = 0";
	    	// 班级id
	    	if(isset($params['classId'])) $where .= " AND `class_id`='{$params['classId']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 截止时间
			if(isset($params['deadline'])) $where .= " AND `updatetime` < '{$params['deadline']}'";
			// xid
			if(isset($params['xid'])) $where .= " AND `xid`='{$params['xid']}' ";
			if(isset($params['categoryByAdminId'])) $where .= " AND `cate_by_admin_id`='{$params['categoryByAdminId']}' ";
			
			$this->db->where($where);
			$this->db->order_by('id', 'DESC');
	    	return $this->db->get(self::$albumCategoryTable)->result_array();
	    }
	    // 获取相册分类信息
	    public function get_album_category_info($categoryId) {
	    	$where = "`id`='{$categoryId}'";
	    	$categoryInfo = $this->db->where($where)->get(self::$albumCategoryTable)->row_array();
	    	return $categoryInfo;
	    }
	    // 获取相册图片
	    public function get_album($params){
	    	$where = " is_delete = 0";
	    	// 班级id
	    	if(isset($params['categoryId'])) $where .= " AND `category_id`='{$params['categoryId']}'";
	    	if(isset($params['classId'])) $where .= " AND `class_id`='{$params['classId']}'";
			if(isset($params['recommend'])) $where .= " AND `image_recommend`='{$params['recommend']}'";
			$this->db->where($where);
			$this->db->order_by('image_sort DESC');
			$this->db->order_by('id', 'DESC');
	    	return $this->db->get(self::$albumTable)->result_array();
	    }
	    // 获取相册图片信息
	    public function get_album_image_info($imageId) {
	    	$where = "`id`='{$imageId}'";
	    	$imageInfo = $this->db->where($where)->get(self::$albumTable)->row_array();
	    	return $imageInfo;
	    }
	    // 获取班级视频列表
	    public function get_video_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_id`)";
			// 班级id数组
			if(isset($params['classIdArr'])) {
				if($params['classIdArr']) {
					$whereStr = " AND (";
					$arr = array();
					foreach($params['classIdArr'] as $classId) {
						array_push($arr, "FIND_IN_SET('{$classId}', `class_id`)");
					}
					$str = implode(' OR ', $arr);
					$whereStr = $whereStr . $str . ")";
					$where .= $whereStr;
				} else {
					$where .= " AND 0";
				}

			}
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}' ";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `video_title` LIKE '%{$params['title']}%'";
			}
			// 过滤视频为空
			if(isset($params['notEmpty'])) {
				$where .= " AND `video_link` != ''";
			}

			$this->db->where($where);
			$this->db->order_by('updatetime', 'DESC');
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$videoTable);
	    	return $this->db->get(self::$videoTable)->result_array();
	    }
	    // 获取班级视频详情
	    public function get_video_info($videoId){
	    	$where = "`id`='{$videoId}'";
	    	$videoInfo = $this->db->where($where)->get(self::$videoTable)->row_array();
	    	return $videoInfo;
	    }

	    // 获取邮件详情
	    public function get_mail_info($mailId){
	    	$where = "`id`='{$mailId}'";
	    	$mailInfo = $this->db->where($where)->get(self::$mailTable)->row_array();

	    	return $mailInfo;
	    }
	    // 获取邮件列表
	    public function get_mail_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 删除状态
	    	if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
	    	// 学校id
	    	if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
	    	// 发送人ID
	    	if(isset($params['userId'])) $where .= " AND `user_id`='{$params['userId']}'";
	    	// 收件人ID
	    	if(isset($params['toUser'])) $where .= " AND FIND_IN_SET('{$params['toUser']}', `mail_to_user`)";
	    	
	    	$this->db->where($where);
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$mailTable);
	    	
	    	return $this->db->order_by("`createtime` DESC")->get(self::$mailTable)->result_array();
		}
		
	    // 获取动态栏目列表
	    public function get_moral_timeline_subject_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
	    	// 删除状态
	    	if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			$this->db->where($where);
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按创建时间
				$this->db->order_by('sort', 'DESC');
				$this->db->order_by('createtime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$moralTimelineSubjectTable);
	    	
	    	return $this->db->get(self::$moralTimelineSubjectTable)->result_array();
	    }
	    // 获取动态栏目详情
	    public function get_moral_timeline_subject_info($id){
	    	$where = "`id`='{$id}'";
	    	$subjectInfo = $this->db->where($where)->get(self::$moralTimelineSubjectTable)->row_array();
	    	return $subjectInfo;
		}
	    // 获取动态列表
	    public function get_moral_timeline_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
	    	// 搜索标题
			if(isset($params['title'])) $where .= " AND `title` LIKE '%{$params['title']}%'";
			// 栏目
			if(isset($params['subjectId'])) $where .= " AND `subject_id`='{$params['subjectId']}'";
			$this->db->where($where);
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按创建时间
				$this->db->order_by('sort', 'DESC');
				$this->db->order_by('createtime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$moralTimelineTable);
	    	
	    	return $this->db->get(self::$moralTimelineTable)->result_array();
	    }
	    // 获取动态详情
	    public function get_moral_timeline_info($id){
	    	$where = "`id`='{$id}'";
	    	$timelineInfo = $this->db->where($where)->get(self::$moralTimelineTable)->row_array();
	    	return $timelineInfo;
		}
        // 获取活动列表
	    public function get_moral_activity_list($params = ""){
			$moralActivityTable = TABLE_PREFIX . self::$moralActivityTable;
			$studentTable = TABLE_PREFIX . self::$studentTable;
			$where = " LEFT JOIN {$studentTable} ON {$studentTable}.id = {$moralActivityTable}.student_id WHERE {$moralActivityTable}.is_delete = 0 AND {$studentTable}.is_delete = 0 ";

	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND {$moralActivityTable}.`school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND {$moralActivityTable}.`campus_id`='{$params['campusId']}' ";
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND {$moralActivityTable}.`is_delete`='{$params['isDelete']}'";
	    	// 搜索学生名称
			if(isset($params['realname'])) $where .= " AND {$studentTable}.`realname` LIKE '%{$params['realname']}%'";
	    	// 审核状态
			if(isset($params['state'])) $where .= " AND {$moralActivityTable}.`state`='{$params['state']}'";
			// 已审核
			if(isset($params['excludePending'])) $where .= " AND {$moralActivityTable}.`state`!='{$params['excludePending']}'";
			// 学生id
			if(isset($params['studentId'])) $where .= " AND {$moralActivityTable}.`student_id` = '{$params['studentId']}'";
			// 创建日期
			if(isset($params['createdate'])) {
				// 传日期就只获取当天最新一条
				$beginTime = $params['createdate'] . ' 00:00:00';
				$endTime = $params['createdate'] . ' 23:59:59';
				$where .= " AND {$moralActivityTable}.createtime >= '{$beginTime}' AND {$moralActivityTable}.createtime <= '{$endTime}'";
			}
			// 传班级id，就不用处理年级id
			if(isset($params['classId'])) {
				$where .= " AND {$studentTable}.`class_id`='{$params['classId']}'";
			} else {
				if(isset($params['classSet'])) {
					if($params['classSet'] === 0 || $params['classSet'] === '0') {
						// 年级不存在班级
						$where .= ' AND 0';
					} else {
						$classIdArr = explode(',', $params['classSet']);
						$str = ' AND (0';
						foreach($classIdArr as $classId) {
							$str .= " OR  {$studentTable}.`class_id` = '{$classId}'";
						}
						$str .= ' )';
						$where .= $str;
					}
				}
			}
			// 排序
			if(isset($params['orderBy'])) {
				$orderSql = ' ORDER BY ' . $params['orderBy'];
			} else {
				$orderSql = ' ORDER BY createtime DESC';
			}
			// 分页
			if(isset($params['pageStart']) && isset($params['pageSize'])) {
				$limitSql = ' LIMIT ' . $params['pageStart']. ',' . $params['pageSize'];
			} else {
				$limitSql = '';
			}
			$mainSql = "SELECT {$moralActivityTable}.*,{$studentTable}.realname,{$studentTable}.class_id,{$studentTable}.headimgurl FROM {$moralActivityTable}" . $where . $orderSql . $limitSql;
			$query = $this->db->query($mainSql);
			$resultList = $query->result_array();
			if(isset($params['getRowNumber'])) {
				return count($resultList);
			} else {
				return $resultList;
			}
	    	return $this->db->get(self::$moralActivityTable)->result_array();
	    }
	    // 获取活动详情
	    public function get_moral_activity_info($id){
	    	$where = "`id`='{$id}'";
	    	$activityInfo = $this->db->where($where)->get(self::$moralActivityTable)->row_array();
	    	return $activityInfo;
		}
	    // 获取评价结果列表
	    public function get_moral_remark_result_list($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 读取指定列
	    	if(isset($params['field'])) $this->db->select($params['field']);
	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
	    	// 删除状态
	    	if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			$this->db->where($where);
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按创建时间
				$this->db->order_by('sort', 'DESC');
				$this->db->order_by('createtime', 'DESC');
			}
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$moralRemarkResultTable);
	    	
	    	return $this->db->get(self::$moralRemarkResultTable)->result_array();
	    }
		// 获取评价结果详情
		public function get_moral_remark_result_info($id){
			$where = "`id`='{$id}'";
			$resultInfo = $this->db->where($where)->get(self::$moralRemarkResultTable)->row_array();
			return $resultInfo;
		}
		// 获取评价列表
		public function get_moral_remark_list($params = ""){
            $moralRemarkTable = TABLE_PREFIX . self::$moralRemarkTable;
			$studentTable = TABLE_PREFIX . self::$studentTable;
			$where = " LEFT JOIN {$studentTable} ON {$studentTable}.id = {$moralRemarkTable}.student_id WHERE {$moralRemarkTable}.is_delete = 0 AND {$studentTable}.is_delete = 0 ";

	    	// 学校id
			if(isset($params['schoolId'])) $where .= " AND {$moralRemarkTable}.`school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND {$moralRemarkTable}.`campus_id`='{$params['campusId']}' ";
	    	// 删除状态
			if(isset($params['isDelete'])) $where .= " AND {$moralRemarkTable}.`is_delete`='{$params['isDelete']}'";
	    	// 搜索学生名称
			if(isset($params['realname'])) $where .= " AND {$studentTable}.`realname` LIKE '%{$params['realname']}%'";
	    	// 审核状态
			if(isset($params['resultId'])) $where .= " AND {$moralRemarkTable}.`result_id`='{$params['resultId']}'";
			// 学生id
			if(isset($params['studentId'])) $where .= " AND {$studentTable}.`id` = '{$params['studentId']}'";
			// 创建日期
			if(isset($params['createdate'])) {
				// 传日期就只获取当天最新一条
				$beginTime = $params['createdate'] . ' 00:00:00';
				$endTime = $params['createdate'] . ' 23:59:59';
				$where .= " AND {$moralRemarkTable}.createtime >= '{$beginTime}' AND {$moralRemarkTable}.createtime <= '{$endTime}'";
			}
			// 传班级id，就不用处理年级id
			if(isset($params['classId'])) {
				$where .= " AND {$studentTable}.`class_id`='{$params['classId']}'";
			} else {
				if(isset($params['classSet'])) {
					if($params['classSet'] === 0 || $params['classSet'] === '0') {
						// 年级不存在班级
						$where .= ' AND 0';
					} else {
						$classIdArr = explode(',', $params['classSet']);
						$str = ' AND (0';
						foreach($classIdArr as $classId) {
							$str .= " OR  {$studentTable}.`class_id` = '{$classId}'";
						}
						$str .= ' )';
						$where .= $str;
					}
				}
			}
			// 排序
			if(isset($params['orderBy'])) {
				$orderSql = ' ORDER BY ' . $params['orderBy'];
			} else {
				$orderSql = ' ORDER BY createtime DESC';
			}
			// 分页
			if(isset($params['pageStart']) && isset($params['pageSize'])) {
				$limitSql = ' LIMIT ' . $params['pageStart']. ',' . $params['pageSize'];
			} else {
				$limitSql = '';
			}
			$mainSql = "SELECT {$moralRemarkTable}.*,{$studentTable}.realname,{$studentTable}.headimgurl,{$studentTable}.class_id FROM {$moralRemarkTable}" . $where . $orderSql . $limitSql;
			$query = $this->db->query($mainSql);
			$resultList = $query->result_array();
			if(isset($params['getRowNumber'])) {
				return count($resultList);
			} else {
				return $resultList;
			}
	    	return $this->db->get(self::$moralRemarkTable)->result_array();
		}
		// 获取评价详情
		public function get_moral_remark_info($id){
			$where = "`id`='{$id}'";
			$remarkInfo = $this->db->where($where)->get(self::$moralRemarkTable)->row_array();
			return $remarkInfo;
		}

        // 获取通讯录列表
	    public function get_phone_book_list($params = ""){
			if(isset($params['schoolId'])) {
				$this->db->where('school_id', $params['schoolId']);
			}
			if(isset($params['campusId'])) {
				$this->db->where('campus_id', $params['campusId']);
			}
			if(isset($params['studentId'])) {
				$this->db->where('student_id', $params['studentId']);
			}
			if(isset($params['isDelete'])) {
				$this->db->where('is_delete', $params['isDelete']);
			}
			// 读取指定列
			if(isset($params['field'])) $this->db->select($params['field']);

			return $this->db->get(self::$phoneBookTable)->result_array();
	    }
	    // 获取通讯录详情
	    public function get_phone_book_info($id){
	    	$where = "`id`='{$id}'";
	    	$info = $this->db->where($where)->get(self::$phoneBookTable)->row_array();
	    	return $info;
		}

		// 获取主题列表
		public function get_subject_content_list($params = ""){
			$where = "1 AND 1";
			// 分页
			if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
			// 读取指定列
			if(isset($params['field'])) $this->db->select($params['field']);
			// 班级id
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_id`)";
			// 班级id数组
			if(isset($params['classIdArr'])) {
				if($params['classIdArr']) {
					$whereStr = " AND (";
					$arr = array();
					foreach($params['classIdArr'] as $classId) {
						array_push($arr, "FIND_IN_SET('{$classId}', `class_id`)");
					}
					$str = implode(' OR ', $arr);
					$whereStr = $whereStr . $str . ")";
					$where .= $whereStr;
				} else {
					$where .= " AND 0";
				}

			}
			// 删除状态
			if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}' ";
			// // 校区id
			// if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}' ";
			// campus_id改成字符串
			// 校区id
			if(isset($params['campusId'])) $where .= " AND FIND_IN_SET('{$params['campusId']}', `campus_id`)";
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `title` LIKE '%{$params['title']}%'";
			}
			// 生效中的
			if(isset($params['effective'])) {
				$now = date('Y-m-d H:i');
				$where .= " AND `begintime` <= '{$now}' AND `endtime` >= '{$now}'";
			}
			// 失效的
			if(isset($params['uneffective'])) {
				$now = date('Y-m-d H:i');
				$where .= " AND (`begintime` > '{$now}' OR `endtime` < '{$now}')";
			}

			$this->db->where($where);
			// 排序
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']['order'], $params['orderBy']['sort']);
			} else {
				// 默认按更新时间
				$this->db->order_by('updatetime', 'DESC');
			}
			// 是否只获取条数
			if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$subjectContentTable);
			
			return $this->db->get(self::$subjectContentTable)->result_array();
		}
		// 获取主题详情
		public function get_subject_content_info($subjectContentId){
			$where = "`id`='{$subjectContentId}'";
			$subjectContentInfo = $this->db->where($where)->get(self::$subjectContentTable)->row_array();
			return $subjectContentInfo;
		}

		// 获取作业提交列表
		public function get_homework_submit_list($params){
			if(isset($params['schoolId'])) {
				$this->db->where('school_id', $params['schoolId']);
			}
			if(isset($params['campusId'])) {
				$this->db->where('campus_id', $params['campusId']);
			}
			if(isset($params['studentId'])) {
				$this->db->where('student_id', $params['studentId']);
			}
			if(isset($params['homeworkId'])) {
				$this->db->where('homework_id', $params['homeworkId']);
			}
			if(isset($params['state'])) {
				$this->db->where('state', $params['state']);
			}
			// 是否最新提交
			if(isset($params['isCurrent'])) {
				$this->db->where('is_current', $params['isCurrent']);
			}
			if(isset($params['isDelete'])) {
				$this->db->where('is_delete', $params['isDelete']);
			}
			if(isset($params['field'])) {
				$this->db->select($params['field']);
			}
			if(isset($params['orderBy'])) {
				$this->db->order_by($params['orderBy']);
			} else {
				// 默认排序
				$this->db->order_by('id DESC');
			}
			// 是否只获取条数
			if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$homeworkSubmitTable);
			return $this->db->get(self::$homeworkSubmitTable)->result_array();
		}

		// 获取管理员相册分类
		public function get_album_category_by_admin_list($params){
			$where = " is_delete = 0";
			// 分页
			if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
			// 学校id
			if(isset($params['schoolId'])) $where .= " AND `school_id`='{$params['schoolId']}'";
			// 校区id
			if(isset($params['campusId'])) $where .= " AND `campus_id`='{$params['campusId']}'";
			// 班级id
			if(isset($params['classId'])) $where .= " AND FIND_IN_SET('{$params['classId']}', `class_ids`)";
			// 搜索标题
			if(isset($params['title'])) {
				$where .= " AND `title` LIKE '%{$params['title']}%'";
			}
			$this->db->where($where);
			// 是否只获取条数
			if(isset($params['getRowNumber'])) return $this->db->count_all_results(self::$albumCategoryByAdminTable);
			return $this->db->get(self::$albumCategoryByAdminTable)->result_array();
		}
			// 获取相册图片信息
			public function get_album_category_by_admin_info($id) {
			$where = "`id`='{$id}'";
			$info = $this->db->where($where)->get(self::$albumCategoryByAdminTable)->row_array();
			return $info;
		}
	}